//
// Created by Administrator on 2024/2/16.
// 双向链表 尾插法
// head tail都是指针 指向链表的头和尾

#include <iostream>
#include <vector>

using namespace std;

struct Node
{
    int v;
    Node *pre;
    Node *next;
};

int main()
{
    vector<int> l = {1, 2, 3, 4, 5, 6};
    Node *head = new Node();
    Node *cur = head;
    for (int i = 0; i < l.size(); ++i)
    {
        Node *t = new Node();
        t->v = l[i];
        t->pre = cur;
        t->next = NULL;
        cur->next = t;
        cur = cur->next;
    }
    Node *tail = new Node();
    tail->pre = cur;

    // 正向输出打印
    cur = head->next;
    while (cur != NULL)
    {
        cout << cur->v << ' ';
        cur = cur->next;
    }
    cout << endl;
    // 逆向输出打印
    cur = tail->pre;
    while (cur->pre != NULL)
    {
        cout << cur->v << ' ';
        cur = cur->pre;
    }
    return 0;
}